﻿<crumbleLibrary:UserControlFilter x:Class="Filter_Misc.FilterMisc"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                          xmlns:crumbleLibrary="clr-namespace:CrumbleLibrary;assembly=CrumbleLibrary"
                                  xmlns:filterMisc="clr-namespace:Filter_Misc"
                                  mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <crumbleLibrary:UserControlFilter.Resources>
        <filterMisc:ControlTypeTemplateSelection x:Key="ControlTypeTemplateSelection">
            <filterMisc:ControlTypeTemplateSelection.CheckBoxTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="50" />
                        </Grid.ColumnDefinitions>
                        <CheckBox Grid.Column="0" Tag="{Binding Name}" IsChecked="{Binding Value}" Content="{Binding LabelText}"/>
                    </Grid>
                </DataTemplate>
            </filterMisc:ControlTypeTemplateSelection.CheckBoxTemplate>
            <filterMisc:ControlTypeTemplateSelection.TextBoxTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="50" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0" Content="{Binding LabelText}"/>
                        <TextBox Grid.Column="1" Tag="{Binding Name}" Text="{Binding Value}"/>
                    </Grid>
                </DataTemplate>
            </filterMisc:ControlTypeTemplateSelection.TextBoxTemplate>
            <filterMisc:ControlTypeTemplateSelection.ListBoxTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="50" />
                        </Grid.ColumnDefinitions>
                        <Label Content="{Binding LabelText}" MinWidth="120" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" FontStretch="Normal" FontWeight="Bold" />
                        <ListBox Grid.Column="0" Grid.Row="1" Tag="{Binding Name}" ItemsSource="{Binding Values}" >
                        </ListBox>
                    </Grid>
                </DataTemplate>
            </filterMisc:ControlTypeTemplateSelection.ListBoxTemplate>
            <filterMisc:ControlTypeTemplateSelection.ComboBoxTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="50" />
                        </Grid.ColumnDefinitions>
                        <Label Content="{Binding LabelText}" MinWidth="120" Grid.Row="0" VerticalAlignment="Center" FontStretch="Normal" FontWeight="Bold" />
                        <ComboBox Grid.Column="0" Grid.Row="1" Tag="{Binding Name}" ItemsSource="{Binding Values}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding Value}" />
                    </Grid>
                </DataTemplate>
            </filterMisc:ControlTypeTemplateSelection.ComboBoxTemplate>
        </filterMisc:ControlTypeTemplateSelection>
    </crumbleLibrary:UserControlFilter.Resources>


    <Grid HorizontalAlignment="Stretch">
        <ItemsControl ScrollViewer.CanContentScroll="False" 
              Name="DynamicFilterArea"
              ItemsSource="{Binding}" 
              ItemTemplateSelector="{StaticResource ControlTypeTemplateSelection}">
        </ItemsControl>
    </Grid>
</crumbleLibrary:UserControlFilter>
